package com.gxm.jar.hutool;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.map.MapUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import lombok.Data;
import org.junit.Test;
import sun.tools.jar.resources.jar;

import java.io.File;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author 郭训民
 * @description: TODO
 * @title: Demo
 * @projectName jsee
 * @date 2021/7/13 19:22
 */
public class Demo {

    @Test
    public void test01(){


/*        String body = HttpUtil.createPost("").execute().body();


        String body1 = HttpUtil.createGet("http://www.baidu.com").execute().body();


        Assert.isNull();


        MapUtil.isEmpty();


        JSONUtil.quote();


        // jar


        // mysql - es
        // canal + kafka + es



        ListUtil.empty();

        List<String> strings = FileUtil.readLines(new File(""), "");*/

    }

    @Test
    public void test02(){
        Bean1 bean1 = new Bean1();
        Bean1 bean12 = new Bean1();
        bean1.setParam1("param1");
        bean1.setParam2("param2");
        bean12.setParam1("param1");
        bean12.setParam2("param2");
        Bean2 bean2 = new Bean2();
        BeanUtil.copyProperties(bean1, bean2);
        List<Bean1> bean1s = new ArrayList<>();
        bean1s.add(bean1);
        bean1s.add(bean12);
        demoTest(bean1s);
        System.out.println(bean2);
    }

    @Test
    public void test04(){
        Bean1 bean1 = new Bean1();
        Bean1 bean2 = new Bean1();
        bean1.setParam2("param2");
        bean2.setParam1("param1");
        BeanUtil.copyProperties(bean1, bean2, CopyOptions.create().setIgnoreNullValue(true));
        System.out.println(bean2);
    }

    @Test
    public void test03(){
        Double a = 0D;
        Double b = 1D;
        List<Double> ds = new ArrayList<>();
        ds.add(a);
        Double minKgs = ds.stream().min(Comparator.comparing(x -> x)).orElse(null);
        System.out.println(minKgs.intValue());
    }

    @Test
    public void test05(){
        String s = "    ";
        String[] s1 = s.split(" ");
        System.out.println(s1);
    }

    private void demoTest(List<Bean1> bean1s) {
        Bean1 param1 = bean1s.stream().filter(item -> item.getParam1().equals("param1")).collect(Collectors.toList()).get(0);
        param1.setParam1("已改");

    }

    @Test
    public void test06(){
        Boolean b = null;
        if (b != null && b) {
            System.out.println("真");
        } else {
            System.out.println("假");
        }
    }

    @Test
    public void test07(){
        String a = "1230001";
        System.out.println(a.length());
        System.out.println(a.substring(a.length() - 4, a.length()));
        double d = 284D;
        BigDecimal b1 = new BigDecimal(String.valueOf(d));
        BigDecimal b2 = new BigDecimal(String.valueOf(3));

        System.out.println(b1.divide(b2, 3, BigDecimal.ROUND_DOWN).doubleValue());
    }

    @Test
    public void test08(){
        List<String> s1 = new ArrayList<>();
        s1.add("1");
        s1.add("2");
        List<String> s2 = new ArrayList<>();
        s2.add("3");
        s2.add("4");
        s2.add("5");
        s1.addAll(s2);
        System.out.println(s2);
    }

    @Test
    public void test09(){
        List<String> s1 = new ArrayList<>();
        s1.add("1");
        s1.add("2");
        System.out.println(String.join(",", s1.subList(0,1)));
    }

    @Test
    public void test10(){
        List<Integer> numbers = new ArrayList<>();
        numbers.add(1);
        numbers.add(2);
        numbers.add(3);
        numbers.add(4);
        numbers.add(5);

        // 获取迭代器对象
        Iterator<Integer> iterator = numbers.iterator();

        // 遍历集合并删除指定元素
        while (iterator.hasNext()) {
            Integer number = iterator.next();
            if (number % 2 == 0) {
                iterator.remove(); // 删除偶数元素
            }
        }
        System.out.println(numbers);
    }

    @Test
    public void test11(){
        Arrays.asList();
        List<String> strs = new ArrayList<>();
        strs.add("2");
        strs.add("1");
        Iterator<String> iterator = strs.iterator();
        while (iterator.hasNext()) {
            String number = iterator.next();
            if ("2".equals(number)) {
                iterator.remove(); // 删除偶数元素
            }
        }
    }

    @Data
    class Bean1 {
        private String param1;
        private String param2;


    }

    @Data
    class Bean2 {
        private String param2;
        private String param3;
    }
}
